package com.principle.ocp;

/**
 * 该类用于演示如果不遵循OCP原则可能产生的后果
 */
public class OcpE1 {
    public static void main(String[] args) {
        Drawable drawable = new Drawable();
        drawable.draw(new Square());
        drawable.draw(new Triangle());
        drawable.draw(new Circle());
    }
}

/**
 * 绘图类
 */
class Drawable{
    public void draw(Shape shape){
        if (shape.m_type == 1){
            drawableC();
        }else if (shape.m_type == 2){
            drawableT();
        }else if (shape.m_type == 3){
            drawableS();
        }

    }
    public void drawableC(){
        System.out.println("Circle is draw");
    }
    public void drawableT(){
        System.out.println("Triangle is draw");
    }
    public void drawableS(){
        System.out.println("Square is draw");
    }
}

/**
 * 图形的基类
 */
class Shape{
    int m_type;
}
/**
 * 以下是图形类
 */
class Circle extends Shape{
   Circle(){
       super.m_type = 1;
   }

}
class Triangle extends Shape{
    Triangle(){
        super.m_type = 2;
    }
}
class Square extends Shape{
    Square(){
        super.m_type = 3;
    }
}

